
<template>

  <div>
    <el-row :gutter="20" style="text-align: center">
      <el-col  justify="center">
        <div v-if="flag" class="grid-content bg-purple">
          <p style="text-align: center ;align-content: center">添加</p>
          <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="用户名" prop="name">
              <el-input type="text" v-model="ruleForm.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="pass">
              <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="确认密码" prop="checkPass">
              <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
              <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
        <el-link  v-if="!flag" type="success" href="http://localhost:8080/html/login.html">跳转登录页面</el-link>
      </el-col>
    </el-row>
  </div>
</template>
<!--<script src="js/vue.js"></script>-->
<!--<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">-->
<!--<script src="https://unpkg.com/element-ui/lib/inedx.js"></script>-->

<script>
// import {axios} from "../js/axios.min";
// Vue.use(axios);
module.exports={
  props:{
    flag:true
  },
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        if (this.ruleForm.checkPass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    };
    var name=(rule, value, callback)=>{
      if (value === '') {
        callback(new Error('用户名不能为空'));
      } else {
        callback();
      }
    }

    return {
      ruleForm: {
        name:'',
        pass: '',
        checkPass: '',

      },
      rules: {
        name: [
          { validator: name, trigger: 'blur' }
        ],
        pass: [
          { validator: validatePass, trigger: 'blur' }
        ],
        checkPass: [
          { validator: validatePass2, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          console.log('submit!');

          this.$emit("submit_form",this.ruleForm)
          // axios({
          //   method:'get',
          //   url:'http://localhost:8080/register'
          // })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}

</script>

<style scoped>
.el-row {
  margin-bottom: 20px;

}
.el-row:last-child {
  margin-bottom: 0;
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  /*background: rgba(163, 222, 232, 0.92);*/
  background-image: linear-gradient(rgba(229, 246, 248, 0.99), rgba(203, 241, 238, 0.97), rgba(111, 221, 246, 0.96));
}

.grid-content {
  margin: auto;
  width: 400px;
  padding: 10px;
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>